/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}import java.util.*;

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        ListNode fast = A;
        ListNode slow = A;
        ListNode mid = null;
        while (fast != null&&fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        mid = slow;

        ListNode head = mid;
        ListNode cur = head.next;
        ListNode Next = null;
        while (cur != null) {
            Next = cur.next;
            cur.next = head;
            head.next = Next;
            head = cur;
            cur = Next;
        }

        while(head != A) {
            if(A.val != head.val) {
                return false;
            }
            if (A.next != head) {
                return true;
            }
            A = A.next;
            head = head.next;
        }
        return true;
    }
}